#include "capacitypanel.h"

CapacityWidget::CapacityWidget( QString title, QWidget* parent ) : QWidget( parent ), m_Title( title )
{
    this->initView();
}

void CapacityWidget::initView()
{
    this->m_TitleLabel  = new QLabel( this->m_Title, this );
    this->m_Gauge       = new GaugePanel( this );
    QVBoxLayout* layout = new QVBoxLayout;

    this->m_TitleLabel->setAlignment( Qt::AlignCenter );
    this->m_TitleLabel->setStyleSheet( QString( "QLabel{color:#ffffff;font-size:18px;}" ) );
    this->m_Gauge->setFixedSize( 100, 100 );
    this->m_Gauge->setValue( 0 );
    QHBoxLayout* gaugeLay = new QHBoxLayout;
    gaugeLay->addStretch( 1 );
    gaugeLay->addWidget( this->m_Gauge );
    gaugeLay->addStretch( 1 );
    layout->addWidget( this->m_TitleLabel );
    layout->addLayout( gaugeLay );
    layout->addStretch( 1 );

    this->setFixedSize( 200, 140 );
    this->setLayout( layout );
}

CapacityPanel::CapacityPanel( QWidget* parent ) : QWidget( parent )
{
    this->initView();
}

void CapacityPanel::initView()
{
    QStringList titles;
    this->m_OxygenGroupBox = new QGroupBox( this );
    this->m_FuelGroupBox   = new QGroupBox( this );
    this->m_OxygenGroupBox->setStyleSheet( QString( "QGroupBox{border:0px solid #79716b;border-radius:6px;background:#433e3a;}" ) );
    this->m_FuelGroupBox->setStyleSheet( QString( "QGroupBox{border:0px solid #79716b;border-radius:6px;background:#433e3a;}" ) );

    titles << "氧1贮箱剩余容量"
           << "氧2贮箱剩余容量"
           << "氧3贮箱剩余容量"
           << "燃1贮箱剩余容量"
           << "燃2贮箱剩余容量"
           << "燃3贮箱剩余容量";

    QHBoxLayout* oLayout = new QHBoxLayout;
    QHBoxLayout* fLayout = new QHBoxLayout;
    oLayout->setSpacing( 0 );
    oLayout->setContentsMargins( 0, 0, 0, 0 );
    oLayout->addStretch( 1 );
    fLayout->setSpacing( 0 );
    fLayout->setContentsMargins( 0, 0, 0, 0 );
    fLayout->addStretch( 1 );

    for ( int i = 0; i < titles.length(); i++ )
    {
        if ( i <= 2 )
        {
            oLayout->addWidget( new CapacityWidget( titles.at( i ), this ) );
        }
        else
        {
            fLayout->addWidget( new CapacityWidget( titles.at( i ), this ) );
        }
    }
    oLayout->addStretch( 1 );
    fLayout->addStretch( 1 );

    this->m_OxygenGroupBox->setLayout( oLayout );
    this->m_FuelGroupBox->setLayout( fLayout );

    QVBoxLayout* layout = new QVBoxLayout;
    layout->setContentsMargins( 0, 0, 0, 0 );
    layout->setSpacing( 8 );
    layout->addWidget( this->m_OxygenGroupBox );
    layout->addWidget( this->m_FuelGroupBox );

    this->setFixedSize( 600, 300 );
    this->setLayout( layout );
}
